package com.tbit.main.pojo;

import cn.hutool.core.util.NumberUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 云bms电池健康度曲线
 *
 * @Author:BUGTian
 * @DATE: 2022/7/19
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class BmsBatteryHealthCurve {
    /**
     * 批次
     */
    private Integer batch;
    /**
     * 批次名称
     */
    private String batchName;
    /**
     * 总数
     */
    private int total;
    /**
     * 小于等于10的占比
     */
    private double oneRatio;
    /**
     * 11-20的占比
     */
    private double twoRatio;
    /**
     * 21-30的占比
     */
    private double threeRatio;
    /**
     * 31-40的占比
     */
    private double fourRatio;
    /**
     * 41-50的占比
     */
    private double fiveRatio;
    /**
     * 51-60的占比
     */
    private double sixRatio;
    /**
     * 61-70的占比
     */
    private double sevenRatio;
    /**
     * 71-80的占比
     */
    private double eightRatio;
    /**
     * 81-90的占比
     */
    private double nineRatio;
    /**
     * 大于等于90的占比
     */
    private double tenRatio;
    /**
     * 小于等于10的数量
     */
    private int oneCount;
    /**
     * 11-20的数量
     */
    private int twoCount;
    /**
     * 21-30的数量
     */
    private int threeCount;
    /**
     * 31-40的数量
     */
    private int fourCount;
    /**
     * 41-50的数量
     */
    private int fiveCount;
    /**
     * 51-60的数量
     */
    private int sixCount;
    /**
     * 61-70的数量
     */
    private int sevenCount;
    /**
     * 71-80的数量
     */
    private int eightCount;
    /**
     * 81-90的数量
     */
    private int nineCount;
    /**
     * 大于等于90的数量
     */
    private int tenCount;

    /**
     * 健康度范围统计
     *
     * @param health
     */
    public void statistics(Integer health) {
        if (health <= 10) {
            oneCount++;
        } else if (health <= 20) {
            twoCount++;
        } else if (health <= 30) {
            threeCount++;
        } else if (health <= 40) {
            fourCount++;
        } else if (health <= 50) {
            fiveCount++;
        } else if (health <= 60) {
            sixCount++;
        } else if (health <= 70) {
            sevenCount++;
        } else if (health <= 80) {
            eightCount++;
        } else if (health <= 90) {
            nineCount++;
        } else {
            tenCount++;
        }
    }

    /**
     * 健康度占比计算
     */
    public void compute() {
        if (total == 0) {
            //总数为0,不进行计算
            return;
        }
        //占比计算
        oneRatio = NumberUtil.div(oneCount, total);
        twoRatio = NumberUtil.div(twoCount, total);
        threeRatio = NumberUtil.div(threeCount, total);
        fourRatio = NumberUtil.div(fourCount, total);
        fiveRatio = NumberUtil.div(fiveCount, total);
        sixRatio = NumberUtil.div(sixCount, total);
        sevenRatio = NumberUtil.div(sevenCount, total);
        eightRatio = NumberUtil.div(eightCount, total);
        nineRatio = NumberUtil.div(nineCount, total);
        tenRatio = NumberUtil.div(tenCount, total);
    }

}
